package com.lucky.back.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lucky.back.pojo.dto.OrderAddNewDTO;
import com.lucky.back.pojo.dto.ProductCategoryAddNewDTO;
import com.lucky.back.pojo.vo.OrderListItenVO;
import com.lucky.back.pojo.vo.ProductCategoryListItemVO;
import com.lucky.back.service.ICategoryService;
import com.lucky.back.service.IOrdersService;
import com.lucky.back.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "07.订单管理模块")
@RestController
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    IOrdersService ordersService;

    @ApiOperation("根据Id查询订单")
    @ApiOperationSupport(order = 420)
    @GetMapping("{id}")
    public JsonResult selectById(@PathVariable Long id){
        List<OrderListItenVO> list = ordersService.selectById(id);
        JsonResult jsonResult = JsonResult.ok();
        jsonResult.setData(list);
        return jsonResult;
    }

    @ApiOperation("查询订单")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult list(){
        List<OrderListItenVO> list = ordersService.list();
        JsonResult jsonResult = JsonResult.ok();
        jsonResult.setData(list);
        return jsonResult;
    }


    @ApiOperation("添加订单")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@Validated OrderAddNewDTO orderAddNewDTO){
        log.debug("11111111");
        ordersService.addNew(orderAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除订单")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(value = "id",name = "id",dataType = "long",required = true)
    @PostMapping("/delete/{id}")
    public JsonResult delete(@PathVariable Long id){
        log.debug("开始处理【删除】的请求，参数：{}", id);
        ordersService.delete(id);
        return JsonResult.ok();
    }
}
